<template>
  <div ref="refMyFav" class="home-my-fav-wrap" @click="handlePathClick">
    <div class="title">
      <div class="flex-center">
        <img src="@/assets/home/icon-myFav.png" alt="">
        <span>我的收藏</span>
      </div>
      <img class="more" src="@/assets/icon/icon-more.png" alt="">
    </div>
    <div class="content">
      <div class="list-item flex-between" v-for="(item,index) in favHomeList" :key="index">
        <div class="left">
          <div class="top flex items-center">
            <label>{{nameFilter(item.industryKey)}}</label>
            <span>{{item.division}}</span>
          </div>
          <p>{{item.quotaName}}</p>
        </div>
        <div class="right">
            {{ itemTime(item) }}
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, watch } from 'vue'
import useQuotaItem from '@/components/QuotaItem/useQuotaItem'
import { useRouter } from 'vue-router'
import { useQuotaStore } from '@/store'
import { storeToRefs } from 'pinia'
import menus from '@/views/keyIndicator/components/menu.js'

defineOptions({
  name: 'MyFav'
})

const quotaStore = useQuotaStore()
const { favHomeList } = storeToRefs(quotaStore)

const emit = defineEmits([])
const router = useRouter()

const itemTime = (item: any) => {
  if(item)
    return useQuotaItem(item).timestr.value
  else
    return ''
}

const handlePathClick = () => {
  router.push({
    path: '/my/myFavourite'
  })
}

const nameFilter = (name: string) => {
  let curArr: any = menus.filter(i=> i.name == name.split('_')[0])
  if(curArr)
  return curArr[0].division
  else
  return ''
}

</script>

<style lang="less" scoped>
.home-my-fav-wrap {
  margin: 13px 11px 12px;
  position: relative;
  .title{
    border-radius: 6px 6px 0px 0px;
    background: linear-gradient(90.17deg, #FFE6D1 0%, #FFF2E7 100%);
    font-weight: bold;
    color: #000000;
    font-size: 13px;
    padding: 9px 0px 13px;
    img{
      width: 18px;
      height: 18px;
      margin-right: 5px;
    }
    .more{
      width: 12px;
      height: 24px;
      position: absolute;
      right: 5px;
      top: 7px;
    }
  }
  .content{
    border-radius: 6px;
    background: rgba(255,255,255,1);
    margin: -5px 0 0;
    padding: 10px 11px;
    line-height: 16px;
    color: #212121;
    font-size: 14px; 
    .list-item{
      border-radius: 5px;
      background: #EEF4FD;
      padding: 9px 12px;
      margin-top: 7px;

      .top{
        label{
          display: inline-block;
          height: 20px;
          line-height: 20px;
          border-radius: 20px;
          background: #3083F426;
          color: #3D76CC;
          font-weight: bold;
          padding: 0 8px;
          font-size: 11px;
          margin-right: 5px;
        }
        span{
          color: #21212199;
          font-size: 13px;
        }
      }
      p{
        margin-top: 6px;
      }
      &:first-child{
        margin-top: 0px;
      }
    }
    .right{
      background: #3D76CC;
      color: #FFFFFF;
      font-size: 11px;
      padding: 0 6px;
      border-radius: 2px 2px 0 2px;
    }
  }
}
</style>
